#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

const int INF = 1 << 20;
const int maxv = 100;
int dis[maxv][maxv];
int n = 6;

int Prim(int v) {
    int tot = 0;
    int lowcost[maxv], closest[maxv], mincost;
    fill(lowcost, lowcost + n + 1, INF);
    for (int j = 1; j <= n; j++) {
        lowcost[j] = dis[v][j];
        closest[j] = v;
    }
    for (int i = 2; i <= n; i++) {
        mincost = INF;
        int k = 1;
        for (int j = 1; j <= n; j++) {
            if (lowcost[j] != 0 && lowcost[j] < mincost) {
                mincost = lowcost[j];
                k = j;
            }
        }
        tot += mincost;
//        cerr << "mincost=" << mincost << endl;
        lowcost[k] = 0;
        for (int j = 1; j <= n; j++) {
            if (dis[k][j] != 0 && dis[k][j] < lowcost[j]) {
                lowcost[j] = dis[k][j];
                closest[j] = k;
            }
        }


    }
    return tot;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            int t;
            cin >> t;
            if (i == j) {
                dis[i][j] = 0;
            } else if (t == 0) {
                dis[i][j] = INF;
            } else {
                dis[i][j] = t;
            }
        }
    cout << Prim(1) << endl;
    return 0;
}
